package com.mzplayer.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MediaData {
    public static final int NORMAL = 0;
    public static final int ASSET = 1;
    public static final int RAW = 2;

    private final String name;
    private final String path;
    private final int type;
    private Map<String, String> header;

    public MediaData(String path, int type) {
        this(null, path, type);
    }

    public MediaData(String name, String path, int type) {
        this(name, path, type, null);
    }

    public MediaData(String name, String path, int type, String header) {
        this.name = name != null ? name : "";
        this.path = type == RAW && path.lastIndexOf(".") != -1 ? path.substring(0, path.lastIndexOf(".")) : path;
        this.type = type >= NORMAL && type <= RAW ? type : NORMAL;
        if (header != null && header.length() != 0) {
            this.header=new HashMap<>();
            Matcher matcher = Pattern.compile("(.+):(.+)\n?", Pattern.DOTALL).matcher(header);
            while (matcher.find()) {
                this.header.put(matcher.group(1).trim(), matcher.group(2).trim());
            }
        }
    }

    public String getName() {
        return name;
    }

    public String getPath() {
        return path;
    }

    public int getType() {
        return type;
    }

    public Map<String, String> getHeader() {
        return header;
    }


}
